package com.spring.annotation_demo;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class FactoryMethodComponent02 {

	private static int i;

	@Bean
	@Qualifier("public")
	public TestBean publicInstance() {
		return new TestBean("publicInstance");
	}

	@Bean
	private TestBean privateInstance() {
		return new TestBean("privateInstance");
	}
	// use of a custom qualifier and autowiring of method parameters
	@Bean
	protected TestBean protectedInstance(
			@Qualifier("public") TestBean spouse,
			@Value("#{privateInstance.name}") String name) {
		//@Value("#{privateInstance.name}   该项迫使TestBean的name属性的修饰修改成可访问的修饰词，如public
		TestBean tb = new TestBean("protectedInstance");
		String s = tb.toString();
		System.out.println(s);

		String s1 = spouse.toString();
		System.out.println("public...s1:"+s1);

		System.out.println("private...name:"+name);
		return tb;
	}



}
